package com.ctg.itrdc.sysmgr.portal.service.utils;

import java.sql.Timestamp;

import com.ctg.itrdc.sysmgr.portal.api.dto.BaseDTO;

public class DTOHelper {

//	public static <T extends SysmgrBaseDTO,K extends SysmgrBaseDTO> void initDTO(T org,K target) {
//		target.setCreateDate(org.getCreateDate());
//		target.setUpdateDate(org.getUpdateDate());
//		target.setStatusDate(org.getStatusDate());
//		target.setCreateStaff(org.getCreateStaff());
//		target.setUpdateStaff(org.getUpdateStaff());
//	}
//	
//	public static <T extends SysmgrBaseDTO,K extends SysmgrBaseDTO> void updateDTO(T org,K target){
//		target.setUpdateDate(org.getUpdateDate());
//		target.setUpdateStaff(org.getUpdateStaff());
//	}
	
	public static <T extends BaseDTO> void updateDTO(T dto) {
		Timestamp timestamp = DateUtils.dateToTimestamp(DateUtils.getNowDate());
		Timestamp createDate = dto.getCreateDate();
		if(createDate==null){
			dto.setCreateDate(timestamp);
		}
		dto.setUpdateDate(timestamp); // 每次都会更新
		Timestamp statusDate = dto.getStatusDate();
		if(statusDate==null){
			dto.setStatusDate(timestamp);
		}
		
		if(dto.getCreateStaff()==null){
			dto.setCreateStaff(-1l);
		}
		if(dto.getUpdateStaff()==null){
			dto.setUpdateStaff(-1l);
		}
	}
}
